﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using He.Common;

namespace He.Web.manage.administrator
{
    public partial class list : He.Web.UI.Manage
    {
        public int psize = 12;
        public int page;
        public int pcount;
        protected void Page_Load(object sender, EventArgs e)
        {
            page = GetInt("page", 0);
            if (!IsPostBack)
            {
                chkLoginLevel("viewAdministrator");
                CookieHelper.Set("LastListUrl", Request.RawUrl);    //保存最后一次访问的列表页Url

                RptBind();
            }
        }

        #region 数据绑定
        private void RptBind()
        {
            He.BLL.administrator bll = new BLL.administrator();
            string strWhere = "user_type>=" + Session["AdminType"].ToString();
            rptList.DataSource = new He.BLL.administrator().GetPageList(psize, page, strWhere, "id desc");
            rptList.DataBind();
            pcount = bll.GetRecordCount(strWhere);
        }
        #endregion

        protected void lbtnDel_Click(object sender, EventArgs e)
        {
            chkLoginLevel("delAdministrator");
            BLL.administrator bll = new BLL.administrator();
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("Check");
                int id = int.Parse(((HiddenField)rptList.Items[i].FindControl("HiddenId")).Value);
                if (cb.Checked)
                {
                    Model.administrator model = bll.GetModel(id);
                    bll.Delete(id);
                }
            }
            SaveLogs("[管理员管理]批量删除管理员");
            JscriptPrint("批量删除成功啦！", Request.RawUrl, "Success");
        }
    }
}
